package com.ml.carManager.ui.my;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.content.ContextCompat;


import com.jaeger.library.StatusBarUtil;
import com.ml.carManager.R;
import com.ml.carManager.net.NetProxyListener;
import com.ml.carManager.ui.dialog.SimpleHintDialog;
import com.ml.carManager.ui.dialog.WaitDialog;
import com.ml.carManager.ui.dialog.listener.OnEnterClickListener;
import com.ml.carManager.ui.login.LoginActivity;
import com.ml.carManager.utils.auth.AuthManager;

import org.jetbrains.annotations.NotNull;

import butterknife.BindView;
import custom.base.entity.base.BaseResponse;
import custom.base.ui.activity.AppManager;
import custom.base.ui.activity.BaseActivity;
import retrofit2.Call;

public class MyActivity extends BaseActivity {
    @BindView(R.id.act_my_exit_login)
    AppCompatButton btnExitLogin;

    private WaitDialog waitDialog;

    @Override
    public boolean initStatusBar() {
        StatusBarUtil.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.app_main_color), 0);
        return false;
    }

    @Override
    public int getLayoutID() {
        return R.layout.act_my;
    }

    @Override
    public void initView(@NonNull @NotNull Bundle savedInstanceState) {
        super.initView(savedInstanceState);

        waitDialog = new WaitDialog(getActivity());
    }

    @Override
    public void initListener() {
        super.initListener();
        btnExitLogin.setOnClickListener(this);
    }


    @Override
    public void onClick(View v, int clickID) {
        if (clickID == btnExitLogin.getId()) {
            SimpleHintDialog dialog = new SimpleHintDialog(getActivity());
            dialog.setContentString("是否确认退出？");
            dialog.setConfirmBtnText("退出登录");
            dialog.setOnEnterClickListener(new OnEnterClickListener() {
                @Override
                public void onEnter() {

                    waitDialog.show();
                    Call<BaseResponse<Object>> call = appApi.logout();
                    call.enqueue(new NetProxyListener<Object>(getALiveNetCallback()) {

                        @Override
                        protected Dialog getDialog() {
                            return waitDialog;
                        }

                        @Override
                        public void onResponseSuccess(Call call, BaseResponse<Object> response) {
//                PlantStatistics plantStatistics = response.getData();
                            AuthManager.getInstance(getActivity()).clearAuth(false);
                            AppManager.getInstance().finishAllActivity();
                            startActivity(LoginActivity.class);
                        }

                    });
                }
            });
            dialog.show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
